/*
	This file is part of Sandbox.

	Copyright (C) 2008  Frederic-Gerald Morcos 	<fred.morcos@gmail.com>
						Marleine Mounir Daoud 	<marleine@gmail.com>

	Sandbox is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Sandbox is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License 
	along with Sandbox.  If not, see <http://www.gnu.org/licenses/>.
*/

#import <glib.h>
#import <app.h>
#import <graph.h>
#import <layout.h>
#import <nodes.h>
#import <search-algo.h>
#import <search-by-type.h>
#import <search-by-borderstyle.h>
#import <search-and-or.h>
#import <search-ui.h> 

static gboolean area_expose(GtkWidget *, GdkEventExpose *, gpointer);
static void nodeapply_click(GtkButton *, gpointer);
static void edgeapply_click(GtkButton *, gpointer);
static void execute_click(GtkButton *, gpointer);
static void save_click(GtkButton *, gpointer);
static gboolean area_press(GtkWidget *, GdkEventButton *, gpointer);
static gboolean area_release(GtkWidget *, GdkEventButton *, gpointer);
static gboolean area_motion(GtkWidget *, GdkEventMotion *, gpointer);
static void scale_valuechanged(GtkRange *, gpointer);
static void wall_toggle(GtkToggleButton *, gpointer);
static gboolean area_config(GtkWidget *, GdkEventConfigure *, gpointer);
static void search_click(GtkButton *button, gpointer data);
static void deselect(GtkButton *button, gpointer data);
static void type_checked(GtkCheckButton *checkbutton, gpointer data);
static void addsearchad_click(GtkButton *button, gpointer data);
static void findsearchad_click(GtkButton *button, gpointer data);
static void minus_click(GtkButton *button, gpointer data);
static void details_click(GtkButton *button, gpointer data);
static void savecomment_click(GtkButton *button, gpointer data);
static void findsearchh_click(GtkButton *button, gpointer data);

SBApp *app = NULL;
Graph *graph = NULL;
Node *drag_node = NULL;
double scaling = 1.0;
int searchnumber = 0;
Node *nodeselected = NULL;

/**
* Main function for the Sandbox Prototype. Main Function for the Sandbox 
* Prototype, it allocs and initializes the sandbox and contains most of the 
* callbacks in the prototype. 
*
* @author Frederic-Gerald Morcos
* @author Marleine Daoud
*/

int main(int argc, char* argv[])
{
	[Gtk init: &argc: &argv];

	app = [[SBApp alloc] init];
	[app->drawarea onExpose: (GCallback) area_expose: NULL];
	[app->drawarea onButtonPress: (GCallback) area_press: NULL];
	[app->drawarea onButtonRelease: (GCallback) area_release: NULL];
	[app->drawarea onMotionNotify: (GCallback) area_motion: NULL];
	[app->generalbox->edgeapply onClicked: (GCallback) edgeapply_click: NULL];
	[app->generalbox->nodeapply onClicked: (GCallback) nodeapply_click: NULL];
	[app->execute onClicked: (GCallback) execute_click: NULL];
	[app->generalbox->scale onValueChanged: (GCallback) scale_valuechanged: 
									NULL];
	[app->walltog onToggled: (GCallback) wall_toggle: NULL];
	[app->drawarea onConfigure: (GCallback) area_config: NULL];
	[app->save onClicked: (GCallback) save_click: NULL];
	[app->searchuibox->searchbebox->searchbutton onClicked: 
						(GCallback) search_click: NULL];
	[app->searchuibox->searchbebox->deselectAllbutton onClicked: 
						(GCallback) deselect: NULL];
	[app->searchuibox->searchbebox->typecheckbutton onChecked: 
						(GCallback) type_checked: NULL];
	[app->searchuibox->searchbebox->savenotebutton onClicked: 
					(GCallback) savecomment_click: NULL];
	[app->searchuibox->searchadbox->addsearchadbutton onClicked: 
					(GCallback) addsearchad_click: NULL];
	[app->searchuibox->searchadbox->findsearchadbutton onClicked: 
					(GCallback) findsearchad_click: NULL];
	[app->searchuibox->searchhistorybox->findsearchhbutton onClicked: 
					(GCallback) findsearchh_click: NULL];
	
	graph = [[Graph alloc] init];
	(void)area_config(NULL, NULL, NULL);
	
	[Gtk main];
	[graph free];

	return 0;
}

static void execute_click(GtkButton *widget, gpointer data) {
	double electro_const = [app->coulconstspin valueInt] / 10.0;
	double spring_const = [app->springconstspin valueInt] / 10.0;
	double timestep = [app->timestepspin valueInt] / 100.0;
	double damping = [app->dampingspin valueDouble] / 10.0;
	int loop = [app->loopspin valueInt];

	g_print("Electrostatic Constant: %g\n", electro_const);
	g_print("Spring Constant: %g\n", spring_const);
	g_print("Timestep: %g\n", timestep);
	g_print("Damping: %g\n", damping);
	g_print("Loop %d times\n", loop);

	[app->execpb configure: 0.0: 0.0: loop];

#pragma omp parallel for
	for (; loop > 0; loop--) {
		[Layout forceLayout: 
				  electro_const: spring_const: 
					   timestep: damping: graph];
		if (!(loop % 200))
		{
			[app->execpb value: [app->execpb value] + 200];
			(void)area_expose([app->drawarea widget], NULL, NULL);
			while (g_main_context_iteration(NULL, FALSE));
		}

		loop--;
	}

	[app->drawarea queueDraw];
}

static gboolean area_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
	static cairo_t *context;
	context = gdk_cairo_create(widget->window);
	gdk_window_clear(widget->window);
	cairo_scale(context, scaling, scaling);
	
	/* clip around the draw area to make things faster */
/*	cairo_rectangle(context, 0.0, 0.0, 
			widget->allocation.width + widget->allocation.width * scaling, 
			widget->allocation.height + widget->allocation.height * scaling);
	cairo_clip(context);
*/
	[graph expose: context];
	cairo_destroy(context);

	return FALSE;
}

/** A callback to create the nodes required. A callback of the Apply button to 
* create the nodes required.
*/

static void nodeapply_click(GtkButton *button, gpointer data) {
	int i = 0;
	[[graph nodeList] clear];
	while (i < [app->generalbox->nodespin valueInt]) {
		if (i % 2)
			[graph addNode: [[[[[Node alloc] init] width: 10] 
				height: 10] comment: "just trying small"]];
		else
			[graph addNode: [[[[[Node alloc] init] width: 20] 
				height: 20] comment: "just trying big"]];
		i++;
	}

	[Nodes nodesRandom: graph];

	edgeapply_click(NULL, NULL);
	[app->drawarea queueDraw];
}

static void edgeapply_click(GtkButton *button, gpointer data) {
	[[graph edgeList] clear];
	const char *text = [app->generalbox->edgecombo activeText];
	if (g_strcmp0(text, "None") == 0)
		;
	if (g_strcmp0(text, "Circular") == 0)
		[Nodes edgesCircular: graph];
	else if (g_strcmp0(text, "Centered") == 0)
		[Nodes edgesCentered: graph];
	else if (g_strcmp0(text, "Interconnected") == 0)
		[Nodes edgesInterconnected: graph];
	else if (g_strcmp0(text, "Binary Tree") == 0)
		[Nodes edgesBinaryTree: graph];

	[app->drawarea queueDraw];
}

/** A callback when the canvas is pressed. A callback when the canvas is pressed 
* to get the node's properties values and display them to the user in the search 
* by example.
*/

static gboolean area_press(GtkWidget *widget, GdkEventButton *event, gpointer data) {
	Node *n = [graph getNodeByPos: event->x: event->y];
	if (event->button == 3)	{		/* right-click */
		if ([n locked] == YES)
			[n unlock];
		else
			[n lock];
	}
	else if (event->button == 1) {	/* dragging */
		drag_node = n;
		
		if(n != NULL) {
			printf("Node Properties: %i, %i, %f, %f, %f, %f, %f, %f,%f, %f, %s\n", 
					[n type], [n lineStyle], [n lineColor].R, 
					[n lineColor].G, [n lineColor].B, 
					[n lineColor].A, [n fillColor].R, 
					[n fillColor].G, [n fillColor].B, 
					[n fillColor].A, [n comment]);

			[app->searchuibox->searchbebox->typecombo setActive: 
								[n type]];
			[app->searchuibox->searchbebox->stylecombo setActive: 
								[n lineStyle]]; 
			[app->searchuibox->searchbebox->linecolorRspin value: 
							[n lineColor].R*255];
			[app->searchuibox->searchbebox->linecolorGspin value: 
							[n lineColor].G*255];
			[app->searchuibox->searchbebox->linecolorBspin value: 
							[n lineColor].B*255];
			[app->searchuibox->searchbebox->linecolorAspin value: 
							[n lineColor].A*255];
			[app->searchuibox->searchbebox->fillcolorRspin value: 
							[n fillColor].R*255];
			[app->searchuibox->searchbebox->fillcolorGspin value: 
							[n fillColor].G*255];
			[app->searchuibox->searchbebox->fillcolorBspin value: 
							[n fillColor].B*255];
			[app->searchuibox->searchbebox->fillcolorAspin value: 
							[n fillColor].A*255];
			gtk_text_buffer_set_text(app->searchuibox->searchbebox->notebuffer, 
							[n comment], -1);
			[app->searchuibox->searchbebox->notetext setBuffer: 
				app->searchuibox->searchbebox->notebuffer];
			nodeselected = n;
			
			/* Glist trial for predicates implementation
			GList *trial =g_list_alloc(); 
			trial = g_list_append(trial, GINT_TO_POINTER (1));
			trial = g_list_append(trial, GINT_TO_POINTER (2));
			trial = g_list_append(trial, GINT_TO_POINTER (3));
			trial = g_list_append(trial, GINT_TO_POINTER (4));
			GList *temp = g_list_last(trial);
			g_print("%d \n", GPOINTER_TO_INT(temp->data));
			temp=g_list_previous(temp);
			g_print("%d \n", GPOINTER_TO_INT(temp->data));
			int* current = temp->data;
			int index = g_list_index(temp, current);
			g_print("%d \n", index); 
			temp = g_list_insert(temp, GINT_TO_POINTER (6), index);
			g_print("%d \n", GPOINTER_TO_INT(temp->data));
			temp = g_list_insert(temp, GINT_TO_POINTER (8), index+1);
			temp=g_list_next(temp);
			g_print("%d \n", GPOINTER_TO_INT(temp->data));
			*/
		}

		if ([n selected])
			[n unselect];
		else
			[n select];
	}
	[app->drawarea queueDraw];
	return FALSE;
}

static gboolean area_release(GtkWidget *widget, GdkEventButton *event, gpointer data) {
	drag_node = NULL;
	return FALSE;
}

static gboolean area_motion(GtkWidget *widget, GdkEventMotion *event, gpointer data) {
	if (drag_node) {
		[[drag_node x: event->x] y: event->y];
		[app->drawarea queueDraw];
	}
	return FALSE;
}

static void scale_valuechanged(GtkRange *range, gpointer data) {
	scaling = [app->generalbox->scale value];
	[app->drawarea queueDraw];
}

static void wall_toggle(GtkToggleButton *toggle, gpointer data) {
	[graph wall: [app->walltog active]];
	[app->drawarea queueDraw];
}

static gboolean area_config(GtkWidget *widget, GdkEventConfigure *event, gpointer data) {
	[[graph width: [app->drawarea widget]->allocation.width]
			height: [app->drawarea widget]->allocation.height];
	[app->drawarea queueDraw];
	return FALSE;
}

static void save_click(GtkButton *button, gpointer data) {
	int w = [app->drawarea widget]->allocation.width;
	int h = [app->drawarea widget]->allocation.height;

	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
	cairo_t *context = cairo_create(surface);
	cairo_set_source_rgb(context, 1.0, 1.0, 1.0);
	cairo_rectangle(context, 0, 0, w, h);
	cairo_fill(context);
	[graph expose: context];
	cairo_surface_write_to_png(surface, "graph.png");
	cairo_destroy(context);
	cairo_surface_destroy(surface);
}

/** A callback to search for the nodes required. A callback of the Find button 
* in the search by example tab to search for the nodes required.
*/

static void search_click(GtkButton *button, gpointer data) {
	//Node *n;	
	char *type = [app->searchuibox->searchbebox->typecombo activeText];
	
	char *style = [app->searchuibox->searchbebox->stylecombo activeText];
	int itype;
	int istyle;
	if (g_strcmp0(type, "Rectangle") == 0)
		itype = 0;
	else if (g_strcmp0(type, "Ellipse") == 0)
			itype = 1;
		else if (g_strcmp0(type, "Triangle") == 0)
				itype = 2;
			else if (g_strcmp0(type, "Note") == 0)
					itype = 3;
	if (g_strcmp0(style, "Continuous") == 0)
		istyle = 0;
		else if (g_strcmp0(style, "Dashed") == 0)
			istyle = 1;
	float linecolorR = ((float) [app->searchuibox->searchbebox->linecolorRspin 
							valueInt])/255.0;
	float linecolorG = ((float) [app->searchuibox->searchbebox->linecolorGspin 
							valueInt])/255.0;
	float linecolorB = ((float) [app->searchuibox->searchbebox->linecolorBspin 
							valueInt])/255.0;
	float linecolorA = ((float) [app->searchuibox->searchbebox->linecolorAspin 
							valueInt])/255.0;
	float fillcolorR = ((float) [app->searchuibox->searchbebox->fillcolorRspin 
							valueInt])/255.0;
	float fillcolorG = ((float) [app->searchuibox->searchbebox->fillcolorGspin 
							valueInt])/255.0;
	float fillcolorB = ((float) [app->searchuibox->searchbebox->fillcolorBspin 
							valueInt])/255.0;
	float fillcolorA = ((float) [app->searchuibox->searchbebox->fillcolorAspin 
							valueInt])/255.0;
	/*ColorRGBA *linecolor = [Node color: ((float) [app->searchuibox->searchbebox->linecolorRspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->linecolorGspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->linecolorBspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->linecolorAspin valueInt])/255.0];*/
	/*ColorRGBA *fillcolor = [Node color: ((float) [app->searchuibox->searchbebox->fillcolorRspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->fillcolorGspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->fillcolorBspin valueInt])/255.0:
				((float) [app->searchuibox->searchbebox->fillcolorAspin valueInt])/255.0];*/
	GtkTextIter end, start;
	gtk_text_buffer_get_start_iter(app->searchuibox->searchbebox->notebuffer, 
									&start);
	gtk_text_buffer_get_end_iter(app->searchuibox->searchbebox->notebuffer, 
									&end);
	char *note = gtk_text_buffer_get_text(app->searchuibox->searchbebox->notebuffer, 
							&start, &end, TRUE);
	
	[SearchAlgo search: [graph nodeList]: itype: istyle: linecolorR: 
		linecolorG: linecolorB: linecolorA: fillcolorR: fillcolorG: 
		fillcolorB: fillcolorA: note];
	
	//printf("%f\n", ((float) [app->searchuibox->searchbebox->linecolorRspin valueInt])/255.0);
	
	/*if (g_strcmp0(type, "Rectangle") == 0)
		[SearchAlgo search: [graph nodeList]: 0];
	else if (g_strcmp0(type, "Ellipse") == 0)
			[SearchAlgo search: [graph nodeList]: 1];
		else if (g_strcmp0(type, "Triangle") == 0)
				[SearchAlgo search: [graph nodeList]: 2];
			else if (g_strcmp0(type, "Note") == 0)
					[SearchAlgo search: [graph nodeList]: 3];*/
	[app->drawarea queueDraw];
}

/** A callback to deselect all the nodes. A callback of the Deselect All button 
* to deselect all the nodes in the canvas.
*/

static void deselect(GtkButton *button, gpointer data) {
	int i = 0;
	while (i < [[graph nodeList] size]) {
		[[[graph nodeList] getItem: i] unselect];
		i++;
	}
	[app->drawarea queueDraw];
}

/** A callback to disactivate the type property. A callback of the type 
* checkbutton to disactivate the type property in the search.
*/

static void type_checked(GtkCheckButton *checkbutton, gpointer data) {
	if([app->searchuibox->searchbebox->typecombo getSensitive])
	{
		[app->searchuibox->searchbebox->typecombo setSensitive: FALSE];
		//if([app->searchuibox->searchbebox->andorTypeStylecombo getSensitive])
			//[app->searchuibox->searchbebox->andorTypeStylecombo setSensitive: FALSE];
	}
	else 
	{
		[app->searchuibox->searchbebox->typecombo setSensitive: TRUE];
		//if(![app->searchuibox->searchbebox->andorTypeStylecombo getSensitive])
			//[app->searchuibox->searchbebox->andorTypeStylecombo setSensitive: TRUE];
	}	
}

/** A callback to destroy a type property added. A callback of the Minus button to 
* destroy the type property added in the dynamic advanced search not needed anymore.
*/

static void minusType_click(GtkButton *button, gpointer data) {
	SearchByTypeUI *temp = (SearchByTypeUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteria);
	GList *tempao = g_list_copy(app->searchuibox->searchandor);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByTypeData *)tempsc->data)->searchbytypeui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteria = 
				g_list_remove(app->searchuibox->searchCriteria, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
	
}

/** A callback to destroy a border style property added. A callback of the Minus 
* button to destroy the border style property added in the dynamic advanced 
* search not needed anymore.
*/

static void minusStyle_click(GtkButton *button, gpointer data) {
	SearchByBorderStyleUI *temp = (SearchByBorderStyleUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteria);
	GList *tempao = g_list_copy(app->searchuibox->searchandor);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByBorderStyleData *)tempsc->data)->searchbyborderstyleui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteria = 
				g_list_remove(app->searchuibox->searchCriteria, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a comment property added. A callback of the Minus 
* button to destroy the comment property added in the dynamic advanced 
* search not needed anymore.
*/

static void minusNote_click(GtkButton *button, gpointer data) {
	SearchByNoteUI *temp = (SearchByNoteUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteria);
	GList *tempao = g_list_copy(app->searchuibox->searchandor);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByNoteData *)tempsc->data)->searchbynoteui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteria = 
				g_list_remove(app->searchuibox->searchCriteria, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a fill color property added. A callback of the Minus 
* button to destroy the fill color property added in the dynamic advanced 
* search not needed anymore.
*/

static void minusFill_click(GtkButton *button, gpointer data) {
	SearchByFillColorUI *temp = (SearchByFillColorUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteria);
	GList *tempao = g_list_copy(app->searchuibox->searchandor);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByFillColorData *)tempsc->data)->searchbyfillcolorui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteria = 
				g_list_remove(app->searchuibox->searchCriteria, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a line color property added. A callback of the Minus 
* button to destroy the line color property added in the dynamic advanced 
* search not needed anymore.
*/

static void minusLine_click(GtkButton *button, gpointer data) {
	SearchByLineColorUI *temp = (SearchByLineColorUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteria);
	GList *tempao = g_list_copy(app->searchuibox->searchandor);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByLineColorData *)tempsc->data)->searchbylinecolorui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandor = 
					g_list_remove(app->searchuibox->searchandor, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteria = 
				g_list_remove(app->searchuibox->searchCriteria, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a type property added. A callback of the Minus button to 
* destroy the type property added in the view/edit search not needed anymore.
*/

static void minusTypee_click(GtkButton *button, gpointer data) {
	SearchByTypeUI *temp = (SearchByTypeUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteriaEdit);
	GList *tempao = g_list_copy(app->searchuibox->searchandorEdit);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByTypeData *)tempsc->data)->searchbytypeui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteriaEdit = 
				g_list_remove(app->searchuibox->searchCriteriaEdit, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
	
}

/** A callback to destroy a border style property added. A callback of the Minus 
* button to destroy the border style property added in the view/edit
* search not needed anymore.
*/

static void minusStylee_click(GtkButton *button, gpointer data) {
	SearchByBorderStyleUI *temp = (SearchByBorderStyleUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteriaEdit);
	GList *tempao = g_list_copy(app->searchuibox->searchandorEdit);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByBorderStyleData *)tempsc->data)->searchbyborderstyleui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteriaEdit = 
				g_list_remove(app->searchuibox->searchCriteriaEdit, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a comment property added. A callback of the Minus 
* button to destroy the comment property added in the view/edit 
* search not needed anymore.
*/

static void minusNotee_click(GtkButton *button, gpointer data) {
	SearchByNoteUI *temp = (SearchByNoteUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteriaEdit);
	GList *tempao = g_list_copy(app->searchuibox->searchandorEdit);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByNoteData *)tempsc->data)->searchbynoteui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteriaEdit = 
				g_list_remove(app->searchuibox->searchCriteriaEdit, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a fill color property added. A callback of the Minus 
* button to destroy the fill color property added in the view/edit 
* search not needed anymore.
*/

static void minusFille_click(GtkButton *button, gpointer data) {
	SearchByFillColorUI *temp = (SearchByFillColorUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteriaEdit);
	GList *tempao = g_list_copy(app->searchuibox->searchandorEdit);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByFillColorData *)tempsc->data)->searchbyfillcolorui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteriaEdit = 
				g_list_remove(app->searchuibox->searchCriteriaEdit, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to destroy a line color property added. A callback of the Minus 
* button to destroy the line color property added in the view/edit 
* search not needed anymore.
*/

static void minusLinee_click(GtkButton *button, gpointer data) {
	SearchByLineColorUI *temp = (SearchByLineColorUI *) data;
	
	GList *tempsc = g_list_copy(app->searchuibox->searchCriteriaEdit);
	GList *tempao = g_list_copy(app->searchuibox->searchandorEdit);
	gboolean done = FALSE;
	//int index;
	
	while(!done)
	{
		
		if (((SearchByLineColorData *)tempsc->data)->searchbylinecolorui == temp)
		{
			//printf("in here\n");
			//index = g_list_index(tempsc, tempsc->data);
			
			if(g_list_next(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)tempao->data 
								widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			else if(g_list_previous(tempsc))
			{
				gtk_widget_destroy([(SearchAndOrUI *)(tempao->data) 
									widget]);
				app->searchuibox->searchandorEdit = 
					g_list_remove(app->searchuibox->searchandorEdit, 
								tempao->data);
			}
			gtk_widget_destroy([temp widget]);
			app->searchuibox->searchCriteriaEdit = 
				g_list_remove(app->searchuibox->searchCriteriaEdit, 
								tempsc->data);
			done = TRUE;
		}
		else 
		{
			tempsc = g_list_next(tempsc);
			if(g_list_next(tempao))
				tempao = g_list_next(tempao);
		}
	}
}

/** A callback to add a property. A callback of the Add Criteria button to 
* add a property in the dynamic advanced search.
*/

static void addsearchad_click(GtkButton *button, gpointer data) {
	const char *searchType = [app->searchuibox->searchadbox->searchadgeneralcombo 
								activeText];	
	if (g_strcmp0(searchType, "Type") == 0)
	{
		SearchByTypeData *searchbytypedata = [[SearchByTypeData alloc] init];
		searchbytypedata->searchbytypeui = [[SearchByTypeUI alloc] init];
		
		searchbytypedata->searchtype = SHAPETYPE;
		searchbytypedata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteria)
			searchbytypedata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[app->searchuibox->searchadbox->searchadvbox packStart: andorui];
			app->searchuibox->searchandor = 
				g_list_append(app->searchuibox->searchandor, andorui);
			[andorui realize];
			//printf("tempandor, %d\n", g_list_length(app->searchuibox->searchandor));
		}
		
		[app->searchuibox->searchadbox->searchadvbox packStart: 
					searchbytypedata->searchbytypeui];
		
		[searchbytypedata->searchbytypeui->minusType onClicked: 
			(GCallback) minusType_click: 
			(gpointer) searchbytypedata->searchbytypeui];
		
		app->searchuibox->searchCriteria = 
			g_list_append(app->searchuibox->searchCriteria, 
						searchbytypedata);
		[searchbytypedata->searchbytypeui->minusType realize];
		[searchbytypedata->searchbytypeui->typecombo realize];
		[searchbytypedata->searchbytypeui->typelabel realize];
		//[searchbytypedata->searchbytypeui->typecheckbutton realize];
		//printf("Length of list in adding %d\n", g_list_next(app->searchuibox->searchCriteria));
	}
	else if (g_strcmp0(searchType, "Border Style") == 0)
	{
		SearchByBorderStyleData *searchbyborderstyledata = 
					[[SearchByBorderStyleData alloc] init];
		searchbyborderstyledata->searchbyborderstyleui = 
					[[SearchByBorderStyleUI alloc] init];
		
		searchbyborderstyledata->searchtype = BORDERSTYLE;
		searchbyborderstyledata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteria)
			searchbyborderstyledata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[app->searchuibox->searchadbox->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandor = 
				g_list_append(app->searchuibox->searchandor, andorui);
		}
		
		[searchbyborderstyledata->searchbyborderstyleui->minusStyle onClicked: 
			(GCallback) minusStyle_click: 
			(gpointer) searchbyborderstyledata->searchbyborderstyleui];
		
		[app->searchuibox->searchadbox->searchadvbox packStart: 
				searchbyborderstyledata->searchbyborderstyleui];
		
		app->searchuibox->searchCriteria = 
			g_list_append(app->searchuibox->searchCriteria, 
						searchbyborderstyledata);
	}
	else if (g_strcmp0(searchType, "Fill Color") == 0)
	{
		SearchByFillColorData *searchbyfillcolordata = 
					[[SearchByFillColorData alloc] init];
		searchbyfillcolordata->searchbyfillcolorui = 
					[[SearchByFillColorUI alloc] init];
		
		searchbyfillcolordata->searchtype = FILLCOLOR;
		searchbyfillcolordata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteria)
			searchbyfillcolordata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[app->searchuibox->searchadbox->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandor = 
				g_list_append(app->searchuibox->searchandor, andorui);
		}
		
		[app->searchuibox->searchadbox->searchadvbox packStart: 
				searchbyfillcolordata->searchbyfillcolorui];
		
		[searchbyfillcolordata->searchbyfillcolorui->minusFill onClicked: 
			(GCallback) minusFill_click: 
			(gpointer) searchbyfillcolordata->searchbyfillcolorui];
				
		app->searchuibox->searchCriteria = 
			g_list_append(app->searchuibox->searchCriteria, 
							searchbyfillcolordata);
	}
	else if (g_strcmp0(searchType, "Line Border Color") == 0)
	{
		SearchByLineColorData *searchbylinecolordata = 
					[[SearchByLineColorData alloc] init];
		searchbylinecolordata->searchbylinecolorui = 
					[[SearchByLineColorUI alloc] init];
		
		searchbylinecolordata->searchtype = LINECOLOR;
		searchbylinecolordata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteria)
			searchbylinecolordata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[app->searchuibox->searchadbox->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandor = 
				g_list_append(app->searchuibox->searchandor, andorui);
		}
		
		[app->searchuibox->searchadbox->searchadvbox packStart: 
				searchbylinecolordata->searchbylinecolorui];
				
		[searchbylinecolordata->searchbylinecolorui->minusLine onClicked: 
			(GCallback) minusLine_click: 
			(gpointer) searchbylinecolordata->searchbylinecolorui];
		
		app->searchuibox->searchCriteria = 
			g_list_append(app->searchuibox->searchCriteria, 
							searchbylinecolordata);
	}
	else if (g_strcmp0(searchType, "Comment") == 0)
	{
		SearchByNoteData *searchbynotedata = [[SearchByNoteData alloc] init];
		searchbynotedata->searchbynoteui = [[SearchByNoteUI alloc] init];
		
		searchbynotedata->searchtype = COMMENT;
		searchbynotedata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteria)
			searchbynotedata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[app->searchuibox->searchadbox->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandor = 
				g_list_append(app->searchuibox->searchandor, andorui);
		}
		
		[searchbynotedata->searchbynoteui->minusNote onClicked: 
			(GCallback) minusNote_click: 
			(gpointer) searchbynotedata->searchbynoteui];
		
		[app->searchuibox->searchadbox->searchadvbox packStart: 
						searchbynotedata->searchbynoteui];
		
		app->searchuibox->searchCriteria = 
			g_list_append(app->searchuibox->searchCriteria, searchbynotedata);
	}
	//printf("Length of list after adding %d\n", g_list_next(app->searchuibox->searchCriteria));
	[app->searchuibox->searchadbox showAll];
}

/** A callback to search for properties. A callback of the Find button in the 
* dynamic advanced search call execute the predicates methods.
*/

static void findsearchad_click(GtkButton *button, gpointer data) {
	if(!app->searchuibox->searchCriteria)
		return;
	//printf("working here b4 values\n");
	GList *temp = app->searchuibox->searchCriteria;
	//printf("temp b4 , %x\n", g_list_next(temp));
	GList *tempandor = app->searchuibox->searchandor;
	//printf("tempandor copy, %d\n", g_list_length(tempandor));
	while(temp)
	{
		//printf("working here in values %d \n", temp->data);
		if(((SearchItem *) temp->data)->searchtype == SHAPETYPE)
		{
			const char *type = 
				[((SearchByTypeData *) temp->data)->searchbytypeui->typecombo 
									activeText];
			if (g_strcmp0(type, "Rectangle") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = RECTANGLE;
				//[SearchAlgo search: [graph nodeList]: 0];
			}
			else if (g_strcmp0(type, "Ellipse") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = ELLIPSE;
				//[SearchAlgo search: [graph nodeList]: 1];
			}
			else if (g_strcmp0(type, "Triangle") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = TRIANGLE;
				//[SearchAlgo search: [graph nodeList]: 2];
			}
			else if (g_strcmp0(type, "Note") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = NOTE;
				//[SearchAlgo search: [graph nodeList]: 3];
			}
		}
		else if(((SearchItem *) temp->data)->searchtype == BORDERSTYLE)
		{
			const char *style = [((SearchByBorderStyleData *) temp->data)->
								searchbyborderstyleui->stylecombo activeText];
			if (g_strcmp0(style, "Dashed") == 0)
			{
				((SearchByBorderStyleData *) temp->data)->borderstyle = DASHED;
			}
			else if (g_strcmp0(style, "Continuous") == 0)
			{
				((SearchByBorderStyleData *) temp->data)->borderstyle = CONTINUOUS;
			}
		}
		else if (((SearchItem *) temp->data)->searchtype == LINECOLOR)
		{
			((SearchByLineColorData *) temp->data)->linecolor.R = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorRspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.G = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorGspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.B = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorBspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.A = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorAspin valueInt])/255.0;
		}
		else if (((SearchItem *) temp->data)->searchtype == FILLCOLOR)
		{
			((SearchByFillColorData *) temp->data)->fillcolor.R = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorRspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.G = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorGspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.B = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorBspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.A = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorAspin valueInt])/255.0;
		}
		else if (((SearchItem *) temp->data)->searchtype == COMMENT)
		{
			GtkTextIter end, start;
			gtk_text_buffer_get_start_iter(((SearchByNoteData *) temp->data)->
				searchbynoteui->notebuffer, &start);
			gtk_text_buffer_get_end_iter(((SearchByNoteData *) temp->data)->
				searchbynoteui->notebuffer, &end);
			char *note = gtk_text_buffer_get_text(((SearchByNoteData *) temp->
				data)->searchbynoteui->notebuffer, &start, &end, TRUE);
			((SearchByNoteData *) temp->data)->comment = note;
		}
		
		//printf("temp here, %x\n", g_list_next(temp));
		if(g_list_length(temp))
		{
			//printf("working here in andor\n");
			if(g_list_length(tempandor))
			{
				//printf("working inside in andor\n");
				const char *andor = [((SearchAndOrUI *) tempandor->data)->
						andorcombo activeText];
				//printf("working after string in andor\n");
				if (g_strcmp0(andor, "And") == 0)
				{
					//printf("working here in and\n");
					((SearchItem *) temp->data)->andOrNull = AND;
				}
				else if (g_strcmp0(andor, "Or") == 0)
				{
					//printf("working here in or\n");
					((SearchItem *) temp->data)->andOrNull = OR;
					//printf(((SearchItem *) temp->data)->andOrNull);
				}
			}
			tempandor = g_list_next(tempandor);
		}
		temp = g_list_next(temp);
	}
	//printf("working here after values\n");
	//printf("Length of list after adding %d\n", g_list_length(app->searchuibox->searchCriteria));
	
	GList *searchCriteriaCopy = NULL;
	GList *tems = app->searchuibox->searchCriteria;
	while(tems)
	{
		searchCriteriaCopy = g_list_append(searchCriteriaCopy, 
				[(SearchItem *)(tems->data) copy]);
		tems = g_list_next(tems);
	}
	GList *searchAndOrCopy = NULL;
	GList *tema = app->searchuibox->searchandor;
	while(tema)
	{
		searchAndOrCopy = g_list_append(searchAndOrCopy, 
				[(SearchAndOrUI *)(tema->data) copy]);
		tema = g_list_next(tema);
	}
	app->searchuibox->searchHistory = g_list_append(app->searchuibox->searchHistory, 
														searchCriteriaCopy);
	app->searchuibox->searchHistoryao = g_list_append(app->searchuibox->searchHistoryao, 
														searchAndOrCopy);
	
	HBox *criteriabox = [[[HBox alloc] init] spacing: 10];
	CheckButton *criteriacheckbutton = [[CheckButton alloc] init];
	Label *criterialabel = [[[Label alloc] init] text: [SearchAlgo createHistoryUI: 
				app->searchuibox->searchHistory]];
	[[criteriabox packStart: criteriacheckbutton] packStart: criterialabel];
	Button *criteriabutton = [[[[Button alloc] init] label:"View Details/Edit"] stock: NO];
	HSeparator *criteriasep = [[HSeparator alloc] init];
	
	/*TextView *criteriatext = [[TextView alloc] init];
	GtkTextBuffer *criteriabuffer = (GtkTextBuffer *) gtk_text_buffer_new (NULL);
	[criteriatext setBuffer: criteriabuffer];
	[criteriatext setEditable: FALSE];
	gtk_text_buffer_set_text(criteriabuffer, [SearchAlgo createHistoryUI: app->searchuibox->searchHistory], -1);
	[criteriatext setBuffer: criteriabuffer];
	*/
	[[[app->searchuibox->searchhistorybox->searchhistoryvbox packStart: 
		criteriabox] packStart: criteriabutton] packStart: criteriasep];
	
	[app->searchuibox->searchhistorybox->findsearchhbutton realize];
	[app->searchuibox showAll];
	
	[criteriabutton onClicked: (GCallback) details_click: (gpointer) searchnumber];
	searchnumber++;
	
	Predicate *predicate =[Predicate createPredicates: 
			g_list_copy(app->searchuibox->searchCriteria)];
	
	//printf("before evaluation %d\n", predicate);
	int i = 0;
	while (i < [[graph nodeList] size]) {
		if ([predicate evaluate: [[graph nodeList] getItem: i]])
		{
			//printf("inside loop evaluate\n");
		   [[[graph nodeList] getItem : i] select];
		}
		i++;
	} 
	[app->drawarea queueDraw];
}

/** A callback to search for properties. A callback of the Find button in the 
* view or edit search call execute the predicates methods.
*/

static void findsearchedit_click(GtkButton *button, gpointer data) {
	if(!app->searchuibox->searchCriteriaEdit)
		return;
	//printf("working here b4 values\n");
	GList *temp = app->searchuibox->searchCriteriaEdit;
	//printf("temp b4 , %x\n", g_list_next(temp));
	GList *tempandor = app->searchuibox->searchandorEdit;
	//printf("tempandor copy, %d\n", g_list_length(tempandor));
	while(temp)
	{
		//printf("working here in values %d \n", temp->data);
		if(((SearchItem *) temp->data)->searchtype == SHAPETYPE)
		{
			const char *type = 
				[((SearchByTypeData *) temp->data)->searchbytypeui->typecombo 
									activeText];
			if (g_strcmp0(type, "Rectangle") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = RECTANGLE;
				//[SearchAlgo search: [graph nodeList]: 0];
			}
			else if (g_strcmp0(type, "Ellipse") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = ELLIPSE;
				//[SearchAlgo search: [graph nodeList]: 1];
			}
			else if (g_strcmp0(type, "Triangle") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = TRIANGLE;
				//[SearchAlgo search: [graph nodeList]: 2];
			}
			else if (g_strcmp0(type, "Note") == 0)
			{
				((SearchByTypeData *) temp->data)->shapetype = NOTE;
				//[SearchAlgo search: [graph nodeList]: 3];
			}
		}
		else if(((SearchItem *) temp->data)->searchtype == BORDERSTYLE)
		{
			const char *style = [((SearchByBorderStyleData *) temp->data)->
								searchbyborderstyleui->stylecombo activeText];
			if (g_strcmp0(style, "Dashed") == 0)
			{
				((SearchByBorderStyleData *) temp->data)->borderstyle = DASHED;
			}
			else if (g_strcmp0(style, "Continuous") == 0)
			{
				((SearchByBorderStyleData *) temp->data)->borderstyle = CONTINUOUS;
			}
		}
		else if (((SearchItem *) temp->data)->searchtype == LINECOLOR)
		{
			((SearchByLineColorData *) temp->data)->linecolor.R = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorRspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.G = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorGspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.B = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorBspin valueInt])/255.0;
			((SearchByLineColorData *) temp->data)->linecolor.A = 
				((float) [((SearchByLineColorData *) temp->data)->
					searchbylinecolorui->linecolorAspin valueInt])/255.0;
		}
		else if (((SearchItem *) temp->data)->searchtype == FILLCOLOR)
		{
			((SearchByFillColorData *) temp->data)->fillcolor.R = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorRspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.G = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorGspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.B = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorBspin valueInt])/255.0;
			((SearchByFillColorData *) temp->data)->fillcolor.A = 
				((float) [((SearchByFillColorData *) temp->data)->
					searchbyfillcolorui->fillcolorAspin valueInt])/255.0;
		}
		else if (((SearchItem *) temp->data)->searchtype == COMMENT)
		{
			GtkTextIter end, start;
			gtk_text_buffer_get_start_iter(((SearchByNoteData *) temp->data)->
				searchbynoteui->notebuffer, &start);
			gtk_text_buffer_get_end_iter(((SearchByNoteData *) temp->data)->
				searchbynoteui->notebuffer, &end);
			char *note = gtk_text_buffer_get_text(((SearchByNoteData *) temp->
				data)->searchbynoteui->notebuffer, &start, &end, TRUE);
			((SearchByNoteData *) temp->data)->comment = note;
		}
		
		//printf("temp here, %x\n", g_list_next(temp));
		if(g_list_length(temp))
		{
			//printf("working here in andor\n");
			if(g_list_length(tempandor))
			{
				//printf("working inside in andor\n");
				const char *andor = [((SearchAndOrUI *) tempandor->data)->
						andorcombo activeText];
				//printf("pointer 2: %x\n", ((SearchAndOrUI *) tempandor->data)->andorcombo);
				//printf("in combo %s\n", andor);
				//printf("working after string in andor\n");
				if (g_strcmp0(andor, "And") == 0)
				{
					//printf("working here in and\n");
					((SearchItem *) temp->data)->andOrNull = AND;
				}
				else if (g_strcmp0(andor, "Or") == 0)
				{
					//printf("working here in or\n");
					((SearchItem *) temp->data)->andOrNull = OR;
				}
				//printf("value %i\n", ((SearchItem *) temp->data)->andOrNull);
			}
			tempandor = g_list_next(tempandor);
		}
		temp = g_list_next(temp);
	}
	//printf("working here after values\n");
	//printf("Length of list after adding %d\n", g_list_length(app->searchuibox->searchCriteria));
	
	GList *searchCriteriaCopy = NULL;
	GList *tems = app->searchuibox->searchCriteriaEdit;
	while(tems)
	{
		searchCriteriaCopy = g_list_append(searchCriteriaCopy, 
				[(SearchItem *)(tems->data) copy]);
		tems = g_list_next(tems);
	}
	GList *searchAndOrCopy = NULL;
	GList *tema = app->searchuibox->searchandorEdit;
	while(tema)
	{
		searchAndOrCopy = g_list_append(searchAndOrCopy, 
				[(SearchAndOrUI *)(tema->data) copy]);
		tema = g_list_next(tema);
	}
	app->searchuibox->searchHistory = g_list_append(app->searchuibox->searchHistory, 
														searchCriteriaCopy);
	app->searchuibox->searchHistoryao = g_list_append(app->searchuibox->searchHistoryao, 
														searchAndOrCopy);
	
	HBox *criteriabox = [[[HBox alloc] init] spacing: 10];
	CheckButton *criteriacheckbutton = [[CheckButton alloc] init];
	Label *criterialabel = [[[Label alloc] init] text: [SearchAlgo createHistoryUI: 
				app->searchuibox->searchHistory]];
	[[criteriabox packStart: criteriacheckbutton] packStart: criterialabel];
	Button *criteriabutton = [[[[Button alloc] init] label:"View Details/Edit"] stock: NO];
	HSeparator *criteriasep = [[HSeparator alloc] init];
	
	/*TextView *criteriatext = [[TextView alloc] init];
	GtkTextBuffer *criteriabuffer = (GtkTextBuffer *) gtk_text_buffer_new (NULL);
	[criteriatext setBuffer: criteriabuffer];
	[criteriatext setEditable: FALSE];
	gtk_text_buffer_set_text(criteriabuffer, [SearchAlgo createHistoryUI: app->searchuibox->searchHistory], -1);
	[criteriatext setBuffer: criteriabuffer];
	*/
	[[[app->searchuibox->searchhistorybox->searchhistoryvbox packStart: 
		criteriabox] packStart: criteriabutton] packStart: criteriasep];
	
	[app->searchuibox->searchhistorybox->findsearchhbutton realize];
	[app->searchuibox showAll];
	
	[criteriabutton onClicked: (GCallback) details_click: (gpointer) searchnumber];
	searchnumber++;
	
	Predicate *predicate =[Predicate createPredicates: 
			g_list_copy(app->searchuibox->searchCriteriaEdit)];
	
	//printf("before evaluation %d\n", predicate);
	int i = 0;
	while (i < [[graph nodeList] size]) {
		if ([predicate evaluate: [[graph nodeList] getItem: i]])
		{
			//printf("inside loop evaluate\n");
		   [[[graph nodeList] getItem : i] select];
		}
		i++;
	} 
	[app->drawarea queueDraw];
}

/** A callback to add a property. A callback of the Add Criteria button to 
* add a property in the edit or view search.
*/

static void addsearchedit_click(GtkButton *button, gpointer data) {
	SearchAdvancedBox *temp = (SearchAdvancedBox *) data;
	const char *searchType = [temp->searchadgeneralcombo activeText];	
	//printf("%s\n", searchType);
	if (g_strcmp0(searchType, "Type") == 0)
	{
		SearchByTypeData *searchbytypedata = [[SearchByTypeData alloc] init];
		searchbytypedata->searchbytypeui = [[SearchByTypeUI alloc] init];
		
		searchbytypedata->searchtype = SHAPETYPE;
		searchbytypedata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteriaEdit)
			searchbytypedata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[temp->searchadvbox packStart: andorui];
			app->searchuibox->searchandorEdit = 
				g_list_append(app->searchuibox->searchandorEdit, andorui);
			[andorui realize];
			//printf("tempandor, %d\n", g_list_length(app->searchuibox->searchandor));
		}
		
		[temp->searchadvbox packStart: 
					searchbytypedata->searchbytypeui];
		
		[searchbytypedata->searchbytypeui->minusType onClicked: 
			(GCallback) minusTypee_click: 
			(gpointer) searchbytypedata->searchbytypeui];
		
		app->searchuibox->searchCriteriaEdit = 
			g_list_append(app->searchuibox->searchCriteriaEdit, 
						searchbytypedata);
		[searchbytypedata->searchbytypeui->minusType realize];
		[searchbytypedata->searchbytypeui->typecombo realize];
		[searchbytypedata->searchbytypeui->typelabel realize];
		//[searchbytypedata->searchbytypeui->typecheckbutton realize];
		//printf("Length of list in adding %d\n", g_list_next(app->searchuibox->searchCriteria));
	}
	else if (g_strcmp0(searchType, "Border Style") == 0)
	{
		SearchByBorderStyleData *searchbyborderstyledata = 
					[[SearchByBorderStyleData alloc] init];
		searchbyborderstyledata->searchbyborderstyleui = 
					[[SearchByBorderStyleUI alloc] init];
		
		searchbyborderstyledata->searchtype = BORDERSTYLE;
		searchbyborderstyledata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteriaEdit)
			searchbyborderstyledata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[temp->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandorEdit = 
				g_list_append(app->searchuibox->searchandorEdit, andorui);
		}
		
		[searchbyborderstyledata->searchbyborderstyleui->minusStyle onClicked: 
			(GCallback) minusStylee_click: 
			(gpointer) searchbyborderstyledata->searchbyborderstyleui];
		
		[temp->searchadvbox packStart: 
				searchbyborderstyledata->searchbyborderstyleui];
		
		app->searchuibox->searchCriteriaEdit = 
			g_list_append(app->searchuibox->searchCriteriaEdit, 
						searchbyborderstyledata);
	}
	else if (g_strcmp0(searchType, "Fill Color") == 0)
	{
		SearchByFillColorData *searchbyfillcolordata = 
					[[SearchByFillColorData alloc] init];
		searchbyfillcolordata->searchbyfillcolorui = 
					[[SearchByFillColorUI alloc] init];
		
		searchbyfillcolordata->searchtype = FILLCOLOR;
		searchbyfillcolordata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteriaEdit)
			searchbyfillcolordata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[temp->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandorEdit = 
				g_list_append(app->searchuibox->searchandorEdit, andorui);
		}
		
		[temp->searchadvbox packStart: 
				searchbyfillcolordata->searchbyfillcolorui];
		
		[searchbyfillcolordata->searchbyfillcolorui->minusFill onClicked: 
			(GCallback) minusFille_click: 
			(gpointer) searchbyfillcolordata->searchbyfillcolorui];
				
		app->searchuibox->searchCriteriaEdit = 
			g_list_append(app->searchuibox->searchCriteriaEdit, 
							searchbyfillcolordata);
	}
	else if (g_strcmp0(searchType, "Line Border Color") == 0)
	{
		SearchByLineColorData *searchbylinecolordata = 
					[[SearchByLineColorData alloc] init];
		searchbylinecolordata->searchbylinecolorui = 
					[[SearchByLineColorUI alloc] init];
		
		searchbylinecolordata->searchtype = LINECOLOR;
		searchbylinecolordata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteriaEdit)
			searchbylinecolordata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[temp->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandorEdit = 
				g_list_append(app->searchuibox->searchandorEdit, andorui);
		}
		
		[temp->searchadvbox packStart: 
				searchbylinecolordata->searchbylinecolorui];
				
		[searchbylinecolordata->searchbylinecolorui->minusLine onClicked: 
			(GCallback) minusLinee_click: 
			(gpointer) searchbylinecolordata->searchbylinecolorui];
		
		app->searchuibox->searchCriteriaEdit = 
			g_list_append(app->searchuibox->searchCriteriaEdit, 
							searchbylinecolordata);
	}
	else if (g_strcmp0(searchType, "Comment") == 0)
	{
		SearchByNoteData *searchbynotedata = [[SearchByNoteData alloc] init];
		searchbynotedata->searchbynoteui = [[SearchByNoteUI alloc] init];
		
		searchbynotedata->searchtype = COMMENT;
		searchbynotedata->ptype = CRITERIA;
		
		if(!app->searchuibox->searchCriteriaEdit)
			searchbynotedata->andOrNull = NUL;
		else {
			SearchAndOrUI *andorui = [[SearchAndOrUI alloc] init];
			[temp->searchadvbox packStart: 
									andorui];
			app->searchuibox->searchandorEdit = 
				g_list_append(app->searchuibox->searchandorEdit, andorui);
		}
		
		[searchbynotedata->searchbynoteui->minusNote onClicked: 
			(GCallback) minusNotee_click: 
			(gpointer) searchbynotedata->searchbynoteui];
		
		[temp->searchadvbox packStart: 
						searchbynotedata->searchbynoteui];
		
		app->searchuibox->searchCriteriaEdit = 
			g_list_append(app->searchuibox->searchCriteriaEdit, searchbynotedata);
	}
	//printf("Length of list after adding %d\n", g_list_next(app->searchuibox->searchCriteria));
	[temp showAll];
}

/** A callback to close a view or edit search criteria. A callback of the View Details/
* edit button to close a view or edit search criteria from the search history.
*/

static void close_click(GtkButton *button, gpointer data) {
	//printf("close here %x\n", data);
	gtk_widget_destroy([(SearchAdvancedBox *) data widget]);
}

/** A callback to view or edit a search criteria. A callback of the View Details/
* edit button to view or edit a search criteria from the search history.
*/

static void details_click(GtkButton *button, gpointer data) {
	int no = (int) data;
	
	GList *sctemps = g_list_nth_data(app->searchuibox->searchHistory, no);
	GList *tempaos = g_list_nth_data(app->searchuibox->searchHistoryao, no);
	//printf("clicked on me %i, %i, %i\n", no, 
		//g_list_length(app->searchuibox->searchHistory), 
		//	g_list_length(app->searchuibox->searchHistoryao));
	
	GList *temps = NULL;
	//SearchItem *tempsi = NULL;
	while(sctemps)
	{
		//tempsi = (SearchItem *)(sctemps->data);
		/*if(tempsi->searchtype == SHAPETYPE)
		{
			SearchByTypeUI *temptui = [((SearchByTypeData *)tempsi)
														->searchbytypeui copy];
			ComboBox *temptc = [((SearchByTypeData *)tempsi)
														->searchbytypeui->typecombo copy];
			//printf("b4 copy: %x, copy: %x\n", ((SearchByTypeData *)tempsi)
											//			->searchbytypeui, temptui);
			//printf("b4 combo copy: %x, copy: %x\n", ((SearchByTypeData *)tempsi)
													//	->searchbytypeui->typecombo, temptc);
			((SearchByTypeData *)tempsi)->searchbytypeui = temptui;
			((SearchByTypeData *)tempsi)->searchbytypeui->typecombo = temptc;
			//printf("after copy: %x, copy: %x\n", ((SearchByTypeData *)tempsi)->searchbytypeui, ((SearchByTypeData *)tempsi)->searchbytypeui->typecombo);
		}*/
		temps = g_list_append(temps, 
				[((SearchItem *)sctemps->data) copy]);
		sctemps = g_list_next(sctemps);
	}
	
	GList *tempao = NULL;
	SearchAndOrUI *tempeao = NULL;
	while(tempaos)
	{
		tempeao = [[SearchAndOrUI alloc] init];
		
		ComboBox *tempeaoc = [tempeao->andorcombo copy];

		//printf("b4 combo copy: %x, copy: %x\n", tempeao->andorcombo, tempeaoc);
		
		tempeao->andorcombo = tempeaoc;
		
		tempao = g_list_append(tempao, tempeao);
		
		//printf("after copy: %x, copy: %x\n", ((SearchAndOrUI *)tempaos->data), ((SearchAndOrUI *)tempao->data));
		tempaos = g_list_next(tempaos);
	}
	
	
	HBox *edittabbox = [[[HBox alloc] init] spacing: 5];
	Label *editlabel = [[[Label alloc] init] text: "Edit"];
	Button *closebutton = [[[[Button alloc] init] label: "x"] stock: YES];
	[[edittabbox packStart: editlabel] packStart: closebutton];
	SearchAdvancedBox *viewedith = [[SearchAdvancedBox alloc] init];
	[app->searchuibox->searchnotebook appendPage: viewedith: edittabbox];
	[edittabbox showAll];
	//[app->searchuibox->searchnotebook realize];
	// printf("%i\n", [app->searchuibox->searchnotebook getNpages]);
	int x = [app->searchuibox->searchnotebook getNpages]-1;
	[app->searchuibox->searchnotebook setCurrentPage: x];
	//[app->searchuibox->searchnotebook showAll];
	[closebutton onClicked: (GCallback) close_click: (gpointer) viewedith];
	
	[viewedith->addsearchadbutton onClicked: (GCallback) addsearchedit_click: (gpointer) viewedith];
	[viewedith->findsearchadbutton onClicked: (GCallback) findsearchedit_click: NULL];
	//[viewedith->findsearchadbutton onClicked: (GCallback) findsearchedit_click: (gpointer) viewedith];
	//temps = g_list_first(temps);
	
	app->searchuibox->searchCriteriaEdit = temps;
	app->searchuibox->searchandorEdit = tempao;
	
	while(temps)
	{	
		//printf("that's %i\n", (int) ((SearchItem *)temps->data)->searchtype);
		if(((SearchItem *) temps->data)->searchtype == SHAPETYPE)
		{
			//printf("here\n");
			((SearchByTypeData *) temps->data)->searchbytypeui = 
					[[SearchByTypeUI alloc] init];
			[viewedith->searchadvbox packStart: 
					((SearchByTypeData *) temps->data)->searchbytypeui];
			[((SearchByTypeData *) temps->data)->searchbytypeui->typecombo 
					setActive: ((SearchByTypeData *) temps->data)->shapetype];
		}
		else if(((SearchItem *) temps->data)->searchtype == BORDERSTYLE)
		{
			//printf("here\n");
			((SearchByBorderStyleData *) temps->data)->searchbyborderstyleui = 
					[[SearchByBorderStyleUI alloc] init];
			[viewedith->searchadvbox packStart: 
					((SearchByBorderStyleData *) temps->data)->searchbyborderstyleui];
			[((SearchByBorderStyleData *) temps->data)->searchbyborderstyleui->stylecombo 
					setActive: ((SearchByBorderStyleData *) temps->data)->borderstyle];
		}
		else if(((SearchItem *) temps->data)->searchtype == LINECOLOR)
		{
			((SearchByLineColorData *) temps->data)->searchbylinecolorui = 
					[[SearchByLineColorUI alloc] init];
			[viewedith->searchadvbox packStart: 
					((SearchByLineColorData *) temps->data)->searchbylinecolorui];
			[((SearchByLineColorData *) temps->data)->searchbylinecolorui->linecolorRspin 
					value: ((SearchByLineColorData *) temps->data)->linecolor.R*255];
			[((SearchByLineColorData *) temps->data)->searchbylinecolorui->linecolorGspin 
					value: ((SearchByLineColorData *) temps->data)->linecolor.G*255];
			[((SearchByLineColorData *) temps->data)->searchbylinecolorui->linecolorBspin 
					value: ((SearchByLineColorData *) temps->data)->linecolor.B*255];
			[((SearchByLineColorData *) temps->data)->searchbylinecolorui->linecolorAspin 
					value: ((SearchByLineColorData *) temps->data)->linecolor.A*255];
		}
		else if(((SearchItem *) temps->data)->searchtype == FILLCOLOR)
		{
			((SearchByFillColorData *) temps->data)->searchbyfillcolorui = 
					[[SearchByFillColorUI alloc] init];
			[viewedith->searchadvbox packStart: 
					((SearchByFillColorData *) temps->data)->searchbyfillcolorui];
			[((SearchByFillColorData *) temps->data)->searchbyfillcolorui->fillcolorRspin 
					value: ((SearchByFillColorData *) temps->data)->fillcolor.R*255];
			[((SearchByFillColorData *) temps->data)->searchbyfillcolorui->fillcolorGspin 
					value: ((SearchByFillColorData *) temps->data)->fillcolor.G*255];
			[((SearchByFillColorData *) temps->data)->searchbyfillcolorui->fillcolorBspin 
					value: ((SearchByFillColorData *) temps->data)->fillcolor.B*255];
			[((SearchByFillColorData *) temps->data)->searchbyfillcolorui->fillcolorAspin 
					value: ((SearchByFillColorData *) temps->data)->fillcolor.A*255];
		}
		else if(((SearchItem *) temps->data)->searchtype == COMMENT)
		{
			//printf("here\n");
			((SearchByNoteData *) temps->data)->searchbynoteui = 
					[[SearchByNoteUI alloc] init];
			[viewedith->searchadvbox packStart: 
					((SearchByNoteData *) temps->data)->searchbynoteui];
			gtk_text_buffer_set_text(((SearchByNoteData *) temps->data)->searchbynoteui->notebuffer, 
							((SearchByNoteData *) temps->data)->comment, -1);
			[((SearchByNoteData *) temps->data)->searchbynoteui->notetext setBuffer: 
				((SearchByNoteData *) temps->data)->searchbynoteui->notebuffer];
			[((SearchByNoteData *) temps->data)->searchbynoteui->notetext realize];
		}
		if(tempao)
		{
			//(SearchAndOrUI *) tempao->data = [[SearchAndOrUI alloc] init];
			//SearchAndOrUI *tempaoui = [[SearchAndOrUI alloc] init];//(SearchAndOrUI *) tempao->data;
			[viewedith->searchadvbox packStart: (SearchAndOrUI *)tempao->data];
			[((SearchAndOrUI *)tempao->data)->andorcombo setActive: ((SearchItem *) temps->data)->andOrNull];
			//printf("pointer 1: %x\n", ((SearchAndOrUI *)tempao->data)->andorcombo);
			//app->searchuibox->searchandorEdit = g_list_append(app->searchuibox->searchandorEdit, (SearchAndOrUI *)tempao->data);
			tempao = g_list_next(tempao);
		}
		temps = g_list_next(temps);
	}
	
	[app->searchuibox showAll];
}

/** A callback to save the comment. A callback of the Save Comment button to 
* save any edited comment in the search by example.
*/

static void savecomment_click(GtkButton *button, gpointer data) {
	GtkTextIter end, start;
	gtk_text_buffer_get_start_iter(app->searchuibox->searchbebox->notebuffer, 
																		&start);
	gtk_text_buffer_get_end_iter(app->searchuibox->searchbebox->notebuffer, &end);
	char *note = gtk_text_buffer_get_text(app->searchuibox->searchbebox->notebuffer, 
															&start, &end, TRUE);
	[nodeselected comment: note];
}

/** A callback to search for criteria. A callback of the Find button in the 
* search history to research any search criteria in the search history list by 
* calling and executing the predicates methods.
*/

static void findsearchh_click(GtkButton *button, gpointer data) {
	if(!app->searchuibox->searchHistory)
		return;
	//printf("working here b4 values\n");
	GList *temp = app->searchuibox->searchHistory;
	//GList *tempaon = app->searchuibox->searchHistoryao;
	printf("temp b4 , %x\n", g_list_length(temp));
	//GList *tempandor = app->searchuibox->searchandor;
	
	while(temp)
	{
		Predicate *predicate =[Predicate createPredicates: temp->data];
		printf("in loop\n");
		//printf("before evaluation %d\n", predicate);
		int i = 0;
		//Node *n;
		while (i < [[graph nodeList] size]) {
			//n = [[graph nodeList] getItem: i];
			//printf("condition %d\n", [predicate evaluate: [[graph nodeList] getItem: i]]);
			if ([predicate evaluate: [[graph nodeList] getItem: i]])
			{
				//printf("inside loop evaluate\n");
				[[[graph nodeList] getItem : i] select];
			}
			i++;
			//printf("selected %i\n", n->selected);
			
		} 
		temp = g_list_next(temp);
		//tempaon = g_list_next(tempaon);
	}
	[app->drawarea queueDraw];
}

